import { http } from "@/utils/http";

/** 获取当前登录用户的详细信息 */
export const getCurrentUserInfo = () => {
  return http.request<any>("get", "/api/user/me");
};

/** 更新当前登录用户的基本信息 */
export const updateCurrentUserInfo = (data: object) => {
  return http.request<any>("put", "/api/user/me", { data });
};

/** 修改当前登录用户密码 */
export const changePassword = (data: {
  oldPassword: string;
  newPassword: string;
  confirmPassword: string;
}) => {
  return http.request<any>("post", "/api/user/change-password", { data });
};

/** 分页获取所有用户列表（管理员接口） */
export const getUserList = (params?: {
  page?: number;
  size?: number;
  keyword?: string;
}) => {
  return http.request<any>("get", "/api/admin/users", { params });
};

/** 创建新用户（管理员接口） */
export const createUser = (data: {
  username: string;
  password: string;
  initialPoints: number;
  enabled: boolean;
  remark: string;
}) => {
  return http.request<any>("post", "/api/admin/users", { data });
};

/** 根据用户ID获取用户详细信息 */
export const getUserDetail = (userId: number) => {
  return http.request<any>("get", `/api/admin/users/${userId}`);
};

/** 调整用户积分（增加或减少） */
export const adjustUserPoints = (
  userId: number,
  amount: number,
  description: string
) => {
  return http.request<any>("post", `/api/admin/users/${userId}/points`, {
    params: { amount, description }
  });
};

/** 重置用户密码为默认密码 */
export const resetUserPassword = (userId: number) => {
  return http.request<any>("post", `/api/admin/users/${userId}/reset-password`);
};

/** 启用或禁用用户 */
export const updateUserStatus = (userId: number, status: number) => {
  return http.request<any>("put", `/api/admin/users/${userId}/status`, {
    params: { status }
  });
};

/** 获取用户相关统计数据 */
export const getUserStats = () => {
  return http.request<any>("get", "/api/admin/users/stats");
};
